import hmyRequest from '@/service'
import notifyFn from '@/utils/res-notify'

//页面通用请求数据

//获取页面content数据
export function getPageListData(url: string, queryInfo: any) {
  return hmyRequest.post({
    url: url,
    data: queryInfo
  })
}

// 删除单个用户数据
export function deletePageData(url: string) {
  return hmyRequest.delete({
    url: url,
    interceptors: {
      responseSuccessFn: (res) => {
        notifyFn({
          message: res.msg,
          type: res.code
        })
        return res
      }
    }
  })
}

// 新建一个数据
export function createPageData(url: string, userInfo: any) {
  return hmyRequest.post({
    url: url,
    data: userInfo,
    interceptors: {
      responseSuccessFn: (res) => {
        notifyFn({
          message: res.msg,
          type: res.code
        })
        return res
      }
    }
  })
}

// 编辑一个数据
export function editPageData(url: string, userInfo: any) {
  return hmyRequest.patch({
    url: url,
    data: userInfo,
    interceptors: {
      responseSuccessFn: (res) => {
        notifyFn({
          message: res.msg,
          type: res.code
        })
        return res
      }
    }
  })
}

//上传图片
export function uploadImg(url: string, data: any) {
  console.log(data)
  const formData = new FormData()
  formData.append('photo', data)
  console.log(formData)
  return hmyRequest.post({
    url: url,
    data: formData,
    headers: { 'Content-Type ': 'multipart/form-data' }
  })
}
